﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style>

    .layui-table-tool > .layui-table-tool-temp {
        padding-right: 0px;
    }
</style>
<script>

    layui.use(['jquery', 'form', 'table', 'common', 'dtree', 'commonTable', 'optimizeSelectOption'], function () {
        var $ = layui.jquery,
            form = layui.form,
            commonTable = layui.commonTable,
            table = layui.table,
            dtree = layui.dtree,
            common = layui.common;
        //加载数据
        wcLoading.close();
        //权限控制(js是值传递)
        toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
        // 初始化树
        var DemoTree = dtree.render({
            elem: "#demoTree",
            height: 'full-15',
            width: '135px',
            method: "GET",
            async: true,
            line: true,  // 显示树线
            scroll: "#toolbarDiv", // 绑定div元素
            icon: ["0", "-1"],  // 显示非最后一级节点图标，隐藏最后一级节点图标
            initLevel: 1,
            url: "/SystemManage/ItemsType/GetTreeGridJson?v=" + new Date().Format("yyyy-MM-dd hh:mm:ss") // 使用url加载（可与data加载同时存在）
        });
        var treeid;
        // 绑定节点点击
        dtree.on("node('demoTree')", function (obj) {
            treeid = obj.param.nodeId;
            $("#txt_keyword").val('');
            $('button[lay-filter="data-search-btn"]').click();//按钮刷新
        });
        //$(function () {
        //    treeView();
        //});
        //function treeView() {
        //    $('#itemTree').treeview({
        //        url: '/SystemManage/ItemsType/GetTreeJson',
        //        onnodeclick: function (node) {
        //            //alert(node.text);  // alert node text property when clicked
        //            $("#txt_keyword").val('');
        //            $('button[lay-filter="data-search-btn"]').click();//按钮刷新
        //        }
        //    });
        //}
        commonTable.rendertable({
            elem: '#currentTableId',
            url: "/SystemManage/ItemsData/GetGridJson",
            where: {
                itemId: "~",
                keyword: "",
            },
            defaultToolbar: [],
            search:false,
            page: false,
            height: 'full-110',
            cols: [[
                { field: 'F_ItemName', title: '名称', width: 120 },
                { field: 'F_ItemCode', title: '编号', width: 120 },
                { field: 'F_SortCode', title: '排序', width: 60 },
                {
                    field: 'F_IsDefault', title: '默认', width: 80,
                    templet: function (d) {
                        if (d.F_IsDefault == true) {
                            return "<span class='layui-btn layui-btn-normal layui-btn-xs'>是</span>";
                        } else {
                            return "<span class='layui-btn layui-btn-warm layui-btn-xs'>否</span>";
                        }
                    }
                }, 
                {
                    field: 'F_EnabledMark', title: '状态', width: 80,
                    templet: function (d) {
                        if (d.F_EnabledMark == true) {
                            return "<span class='layui-btn layui-btn-normal layui-btn-xs'>有效</span>";
                        } else {
                            return "<span class='layui-btn layui-btn-warm layui-btn-xs'>无效</span>";
                        }
                    }
                }, 
                {
                    field: 'F_CreatorTime', title: '创建时间', width: 120,
                    templet: function (d) {
                        if (d.F_CreatorTime) {
                            var time = new Date(d.F_CreatorTime);
                            return time.Format("yyyy-MM-dd");
                        }
                        return '';
                    }
                },
                { field: 'F_Description', title: '介绍', minWidth: 100 },
            ]]
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //if (!$("#itemTree").getCurrentNode()) {
            //    return false;
            //}
            //var itemId = $("#itemTree").getCurrentNode().id;
            //执行搜索重载
            commonTable.reloadtable({
                elem: 'currentTableId',
                page: false,
                where: {
                    itemId: treeid,
                    keyword: data.field.txt_keyword,
                },
            });
            item = null;
            return false;
        });
        // 监听搜索操作
        form.on('submit(item-search-btn)', function (data) {
            // 调用内置函数搜索节点
            DemoTree.fuzzySearch(data.field.item_keyword);
            return false;
        });
        var item;
        table.on('row(currentTableFilter)', function (obj) {
            obj.tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
            item = obj;
        })
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听操作
                if (!treeid) {
                    return false;
                }
                common.modalOpen({
                    title: "添加字典",
                    url: "/SystemManage/ItemsData/Form?itemId=" + treeid,
                    width: "450px",
                    height: "350px",
                });
            }
            else if (obj.event === 'delete') {
                if (item == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.deleteForm({
                    url: "/SystemManage/ItemsData/DeleteForm",
                    param: { keyValue: item.data.F_Id },
                    success: function () {
                        common.reload('data-search-btn');
                    }
                });
            }
            else if (obj.event === 'edit') {
                if (item == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "编辑字典",
                    url: "/SystemManage/ItemsData/Form?itemId=" + treeid + "&keyValue=" + item.data.F_Id,
                    width: "450px",
                    height: "350px",
                });
            }
            else if (obj.event === 'details') {
                if (item == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "查看字典",
                    url: "/SystemManage/ItemsData/Details?keyValue=" + item.data.F_Id,
                    width: "450px",
                    height: "350px",
                    btn: []
                });
            }
            else if (obj.event === 'itemstype') {
                common.openNewTabByIframe({
                    title: "分类管理",
                    href: "/SystemManage/ItemsType/Index",
                    checkOpen: false
                });
            }
            return false;
        });
    });
</script>
<div class="layui-fluid" style="padding:0 0px">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md4 layui-col-xs5">
            <div class="layui-card" style="text-align:left;overflow: auto;" id="toolbarDiv">
                <fieldset class="table-search-fieldset" style="border:1px solid #e6e6e6">
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <input type="text" id="item_keyword" name="item_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="item-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </fieldset>
                <ul id="demoTree" class="dtree" data-id="0"></ul>
            </div>
        </div>
        <div class="layui-col-md8 layui-col-xs7">
            <div class="layui-card" style="padding: 5px;">
                <fieldset class="table-search-fieldset" style="border:1px solid #e6e6e6">
                    @*<legend>搜索信息</legend>*@
                    <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input" placeholder="">
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                            </div>
                        </div>
                    </form>
                </fieldset>
                <script type="text/html" id="toolbarDemo">
                    <div class="layui-btn-container" id="toolbar">
                        <button id="NF-add" authorize="yes" class="layui-btn layui-btn-sm data-add-btn layui-hide" lay-event="add"><i class="layui-icon">&#xe654;</i>新建</button>
                        <button id="NF-edit" authorize="yes" class="layui-btn layui-btn-sm layui-btn-warm data-edit-btn layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                        <button id="NF-delete" authorize="yes" class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                        <button id="NF-details" authorize="yes" class="layui-btn layui-btn-sm layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>查看</button>
                        <button id="NF-itemstype" authorize="yes" class="layui-btn layui-btn-sm  data-itemstype-btn layui-hide" lay-event="itemstype"> <i class="fa fa-key"></i>分类管理</button>
                    </div>
                </script>
                <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
            </div>
        </div>
    </div>
</div>
